
{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" lay-event="add"  class="layui-btn {:node('Cost/add')} layui-btn-sm">计算分摊</button>
        <button type="button" lay-event="reload"  class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
    </div>
</script>


<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn   layui-btn-xs {:node('Merchant_money/detail')}" data-title="编辑" lay-event="detail"><i class="layui-icon">&#xe642;</i></a>
    <a href="javascript:;" class="layui-btn  layui-btn-danger layui-btn-xs {:node('Merchant_money/del')}" data-title="删除" lay-event="del"><i class="layui-icon"></i></a>

</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky','opTable','laydate'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var opTable = layui.opTable;
        var laydate = layui.laydate;
        form.render();
        laydate.render({
            elem: '#settlement_time'
            ,type: 'month',
            trigger: 'click'
        });
        form.render();
        var myTables = table.render({
            elem: '#table_id',
            url:"{:url('index')}",
            where: { info_type: 2},
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:20
                ,limits:[10,20,30,50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                { title: '月份', field: 'dateTime'},
                { title: '峰单价(元)', field: 'fmoney'},
                { title: '谷单价(元)', field: 'gmoney'},
                { title: '平单价(元)', field: 'pmoney',},
                { title: '零售单价',field: 'linmoney'},
                { title: '写字楼分摊单价',field: 'tmoney'},
                { title: '商场分摊单价',field: 'stmoney'},
                { title: '供电局总电量',field: 'alluse'},
                //{ title: '创建时间',width:'20%', field: 'create_time',templet:function (item){return layui.util.toDateString((item.create_time)*1000)}},
                {templet: '#operationTpl', width: 240,align: 'center', title: '操作', fixed:'right'}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });

        //导出事件
        $('#export').on('click',function () {
            var merchant_id = $('#merchant_id').val() ;
            var contract_code = $('#contract_code').val() ;
            var pointId = $('#pointId').val() ;
            var pay_status = $('#pay_status').val() ;
            var url = "{:url('export')}"+'?pay_status='+pay_status+ "&pointId=" + pointId + "&export=" + 1+ "&merchant_id=" + merchant_id+ "&contract_code=" + contract_code;
            window.open(url);
        });

        //导出时阻止页面刷新
        $(".layui-form").submit(function (e) {
            e.preventDefault();
        })
        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="detail"){
                lucky.CreateOpenForm("编辑","{:url('detail')}?id="+data.id);
                return false;
            }else if(layEvent==="del"){
                lucky.FormatData(_id,"{:url('del')}");
            }else if(layEvent==="edit"){
                lucky.CreateOpenForm("审核提交","{:url('common/costEdit')}?id=" + _id);
                return false;
            }else if(layEvent==="print"){
                lucky.CreateOpenForm("打印","{:url('common/costPrint')}?id=" + _id,'85%');
                return false;
            }else if(layEvent==="invoice"){
                var datas = {} ;
                datas.id      = _id ;   //  购买数量
                $.ajax({
                    url:"{:url('invoice')}",
                    type:"post",
                    data: datas,
                    dataType:"json",
                    success:function(data){
                        layer.msg(data.msg,{icon:15,time:1000,shade:0.3});
                        window.location.reload();
                    }
                });
                return false;
            }
        });
        table.on('toolbar(table_id)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if(obj.event==="add"){
                lucky.CreateOpenForm("计算分摊","{:url('add')}");
                return false;
                // adminAdd
            } else if(obj.event==="adminAdd"){
                lucky.CreateOpenForm("添加人工缴费用","{:url('adminAdd')}");
                return false;
            }else if(obj.event==="close"){
                opTables.closeAll();
            }else if(obj.event==="open"){
                opTables.openAll();
            }else if(obj.event==="detail"){
                lucky.CreateOpenForm("订单详情","{:url('detail')}");
                return false;
            }else if(obj.event==="reload"){
                lucky.CreateReload();
            }else if(obj.event==="del"){
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.FormatData(id,"{:url('del')}");
                return  false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script >

{/block}
